<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <script>
        window.onload = function() {
            var user = document.getElementById('user');
            user.onblur = function() {
                var xhr = null;
                if (window.XMLHttpRequest) {
                    xhr = new XMLHttpRequest()
                } else {
                    //code for ie6,ie5
                    xhr = new ActiveXObject("Microsoft,XMLHTTP");
                }
                var username = user.value;
                var pas = document.getElementById('password').value;
                var path = 'username=' + username + '& password=' + pas;
                xhr.open("post", './post.php');
                //设置请求头(POST)
                xhr.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
                xhr.send(path);
                xhr.onreadystatechange = function() {
                    if (xhr.readyState == 4) {
                        if (xhr.status == 200) {
                            var span = document.getElementById('info');
                            span.innerHTML = xhr.responseText;
                        }
                    }
                }
            }
        }
    </script>
</head>

<body>
    <form action="">
        用户名:
        <input type='text' id="user">
        <span id='info'></span>
        <br> 密码:
        <input type="text" id='password'>
        <br>
        <input type="button" value="提交" id='btn'>
    </form>
</body>

</html>